class Solution {
public:
    vector<int> countBits(int num) {
        vector<int> result(num + 1);
        result[0] = 0;
        for(int i = 1; i <= num; i *= 2)
        {
            for(int j = 0; j + i <= num && j < i; j++)
            {
                result[j + i] = result[j] + 1;
            }
        }
        return result;
    }
};
